package com.gin.no_gay_alliance.viewmodel;

import android.os.Parcel;
import android.os.Parcelable;

import com.gin.nga.enums.SubForumType;
import com.gin.nga.utils.ForumIconUtils;

import java.io.Serializable;

/**
 * 键值对
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/11 10:57
 **/
public class KeyValue implements Parcelable {
    public static final Creator<KeyValue> CREATOR = new Creator<KeyValue>() {
        @Override
        public KeyValue createFromParcel(Parcel in) {
            return new KeyValue(in);
        }

        @Override
        public KeyValue[] newArray(int size) {
            return new KeyValue[size];
        }
    };
    public String key;
    public Serializable value;

    public KeyValue(String key, Serializable value) {
        this.key = key;
        this.value = value;
    }

    protected KeyValue(Parcel in) {
        key = in.readString();
    }

    /**
     * 转换为入口数据
     *
     * @return 入口数据
     */
    public EntryData toEntryData() {
        EntryData data = new EntryData();
        data.id = Long.parseLong(String.valueOf(value));
        data.name = key;
        data.type = SubForumType.FORUM;
        data.icon = ForumIconUtils.getBigIconUrl(data.id);
        return data;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(key);
    }
}
